package iblink.adapter.request;

import java.util.List;

import iblink.adapter.IBClient;
import iblink.core.ScannerArgs;
import iblink.core.ScannerData;
import iblink.event.ScannerDataResponseEvent;
import iblink.exception.IBLinkException;
import packutil.idgen.IIdGenerator;

public class ScannerDataRequest extends ARequest {

	private final ScannerArgs scannerArgs;
	
	private List<ScannerData> scannerDataList;
	
	protected ScannerDataRequest(IBClient ibClient,
			IIdGenerator requestIdGenerator, ScannerArgs scannerArgs) {
		super(ibClient, requestIdGenerator);
		this.scannerArgs = scannerArgs;
	}

	@Override
	protected void execute(IBClient cli, int requestId) {
		cli.reqScannerSubscription(requestId, scannerArgs);
		ScannerDataResponseEvent responseEvent = (ScannerDataResponseEvent) waitForResponse();
		cli.cancelScannerSubscription(requestId);
		scannerDataList = responseEvent.getScannerDataList();
	}
	
	public List<ScannerData> getScannerData() {

		if (!executed)
			throw new IBLinkException(
					"Trying to get scanner data but request has not yet been executed");

		return scannerDataList;
	}
}